<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title>修正多个错误</title>
</head>
<body>
<form action="" name="form">
    <label for="text1"><input type="text" id="text1" name="text1"></label>
    <br>
    <label for="checkbox1">CheckBox 1 <input type="checkbox" id="checkbox1" name="checkbox1"></label>
    <br>
    <label for="checkbox2">CheckBox 2 <input type="checkbox" id="checkbox2" name="checkbox2"></label>
    <br>
    <label for="text2"><input type="text" id="text2" name="text2"></label>
    <p>
        <label for="submit"><input type="submit" id="submit" name="submit" value="Submit"></label>
    </p>
</form>
<script>
    function checkForm(e) {
        var count = 0;
        var form = document.form;

        while (count < form.length) {
            if (form.elements[count].type == 'text' && form.elements[count].value == '') {
                alert('Plesase complete all form elements');
                form.elements[count].focus();
                e.preventDefault();
                break;
            }
            count++;
        }
    }

    document.form.addEventListener('submit', checkForm);
</script>
</body>
</html>